package com.example.demo.proxy2;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class MyInvocationHandler implements InvocationHandler {
    private final Object target;

    public MyInvocationHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("调用方法：" + method.getName() + " 之前");
        Object result = method.invoke(target, args); // 调用目标对象的方法
        System.out.println("调用方法：" + method.getName() + " 之后");
        return result;
    }
}
